/*
 * @Author: 晴鸢. 3013433857@qq.com
 * @Date: 2025-09-27 10:50:33
 * @LastEditors: 晴鸢. 3013433857@qq.com
 * @LastEditTime: 2025-09-27 11:05:52
 * @FilePath: /Learn/sem_cp/Task.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once
#include <iostream>
#include <string>
using namespace std;
string opers="+-*/%";
enum
{
    divzero = 1,
    modzero,
    unknown
};
class Task
{
public:
    Task()
    {}
    Task(int x, int y, char op)
        : _data1(x), _data2(y), _oper(op), _result(0), _exitcode(0)
    {
    }
    void run()
    {
        switch (_oper)
        {
        case '+':
            _result = _data1 + _data2;
            break;
        case '-':
            _result = _data1 - _data2;
            break;
        case '*':
            _result = _data1 * _data2;
            break;
        case '/':
        {
            if (_data2 == 0)
                _exitcode = divzero;
            else
                _result = _data1 / _data2;
        }
        break;
        case '%':
        {
            if (_data2 == 0)
                _exitcode = modzero;
            else
                _result = _data1 % _data2;
        }
        break;
        default:
            _exitcode = unknown;
            break;
        }
    }
    string Getresult()
    {
        string r = to_string(_data1);
        r += _oper;
        r += to_string(_data2);
        r += "=";
        r += to_string(_result);
        r += "[code:";
        r += to_string(_exitcode);
        r += "]";
        return r;
    }
    string  getTask()
    {
        string r = to_string(_data1);
        r += _oper;
        r += to_string(_data2);
        r += "=?";
        return r;
    }
    ~Task()
    {}

private:
    int _data1;
    int _data2;
    char _oper;
    int _result;
    int _exitcode;
};
